
#
# Copyright © 2005-2010 Instigate CJSC, Armenia
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

$(call check_variable,setup_file)

ifndef build_type
$(warning 'build_type' is not specified during setup process, \
	  build_type=debug default value will be used)
build_type:=debug
else
ifneq ($(build_type),release)
ifneq ($(build_type),debug)
$(error 'build_type' should either be set to 'release' or 'debug')
endif
endif
endif

ifndef link_type
$(warning 'link_type' is not specified during setup process, \
	  link_type=dynamic default value will be used)
link_type:=dynamic
else
ifneq ($(link_type),dynamic)
ifneq ($(link_type),static)
$(error 'link_type' should either be set to 'dynamic' or 'static'. \
	Please correct it in $(setup_file) file)
endif
endif
endif

ifndef use_sdk
$(warning 'use_sdk' is not specified during setup process, \
	  use_sdk=no default value will be used)
use_sdk:=no
else
ifneq ($(use_sdk),yes)
ifneq ($(use_sdk),no)
$(error 'use_sdk' should either be set to 'yes' or 'no')
endif
endif
endif

.PHONY: setup
setup: clean
ifneq ($(wildcard $(setup_file)),)
	@echo "Deleting old setup file ..."
	@rm -f $(setup_file)
endif
	@echo "Generating new setup file ... "
	@echo "" > $(setup_file)
	@echo "# THIS FILE IS READONLY !!!" >> $(setup_file)
	@echo "#" >> $(setup_file)
	@echo "# This file can be changed by entering" >> $(setup_file)
	@echo "# \"make setup use_sdk=<use_sdk> make setup" >> $(setup_file)
	@echo "# \build_type=<build_type> link_type=<link_type>\"" \
		>> $(setup_file)
	@echo "# command from command line." >> $(setup_file)
	@echo "# <build_type> must be either 'debug' or 'release'" >> \
		$(setup_file)
	@echo "# <link_type> must be either 'dynamic' or 'static'" >> \
		$(setup_file)
	@echo "# <use_sdk> must be either 'yes' or 'no'" >> \
		$(setup_file)
	@echo "" >> $(setup_file)
	@echo "export build_type:=$(build_type)" >> $(setup_file)
	@echo "export link_type:=$(link_type)" >> $(setup_file)
	@echo "export use_sdk:=$(use_sdk)" >> $(setup_file)
	@chmod 444 $(setup_file)
	@echo "-------------------------------------"
	@echo "         BUILD CONFIGURATION         "
	@echo "         -------------------         "
	@echo "    USE SDK = $(use_sdk)"
	@echo "    BUILD TYPE = $(build_type)"
	@echo "    LINK TYPE = $(link_type)"
	@echo "-------------------------------------"

include $(mkf_path)/clean.mk

